/*
 * AppRepository.java July 2009
 *
 * Copyright (C) 2009, Quirino Zagarese <quirino@laszloitalia.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 */
package org.eu4ria.core;


import java.util.Collection;
import java.util.Hashtable;

import org.eu4ria.Application;

public class AppRepository {

	private static AppRepository instance;

	private Hashtable<String, Application> applications = new Hashtable<String, Application>();

	private Hashtable<String, String> hashBindings = new Hashtable<String, String>();

	private AppRepository(){

	}

	public static AppRepository getInstance() {
		if(instance == null){
			instance = new AppRepository();
		}
		return instance;
	}


	public void addApplication(String name, Application app){
		String hash = HashFunctions.getMD5(name);
		applications.put(name, app);
		app.setHash(hash);
		hashBindings .put(hash, name);
	}

	public Application getApplication(String path){
		return applications.get(path);
	}

	public Application getApplicationByHash(String hash){
		return applications.get(hashBindings.get(hash));
	}

	public Collection<Application> getApplications(){
		return applications.values();
	}

	public void removeApplication(String path){
		applications.remove(path);
	}


}
